package com.zhangzhan.controller;

import com.zhangzhan.domain.commcon.ResponseResult;
import com.zhangzhan.domain.dto.LinkDto;
import com.zhangzhan.domain.dto.LinkListDto;
import com.zhangzhan.domain.dto.SaveLinkDto;
import com.zhangzhan.domain.vo.PageVO;
import com.zhangzhan.service.LinkService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 张一恒
 * @version 1.0
 */
@RestController
@RequestMapping("/content/link")
public class LinkController {

    @Autowired
    LinkService linkService;

    /**
     * @description 分页查询
     * @param pageNum
     * @param pageSize
     * @param dto
     * @return com.zhangzhan.domain.commcon.ResponseResult<com.zhangzhan.domain.vo.PageVO>
     * @author 31115
     * @date 2022/12/8 17:16
     */
    @GetMapping("/list")
    public ResponseResult<PageVO> listLink(Integer pageNum, Integer pageSize, LinkListDto dto) {
        return linkService.listLink(pageNum,pageSize,dto);
    }

    /**
     * @description 新增
     * @param dto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 17:27
     */
    @PostMapping
    public ResponseResult saveLink(@RequestBody SaveLinkDto dto){
        return linkService.saveLink(dto);
    }

    /**
     * @description 修改前回显
     * @param id
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 17:43
     */
    @GetMapping("{id}")
    public ResponseResult selectById(@PathVariable("id") Long id){
        return linkService.selecyById(id);
    }

    /**
     * @description 修改
     * @param dto
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 17:47
     */
    @PutMapping
    public ResponseResult updateLink(@RequestBody LinkDto dto){
        return linkService.updateLink(dto);
    }

    /**
     * @description 删除
     * @param ids
     * @return com.zhangzhan.domain.commcon.ResponseResult
     * @author 31115
     * @date 2022/12/8 17:48
     */
    @DeleteMapping("{id}")
    public ResponseResult deleteLink(@PathVariable("id") Long[] ids){
        return linkService.deleteLinkByIds(ids);
    }
}
